
package hasthi.container.notifier;

import hasthi.common.HasthiException;
import hasthi.common.ManagementNotifier;
import hasthi.common.constants.HasthiConstants;
import hasthi.container.SimpleMessageContext;
import hasthi.container.UnicastContianier;
import hasthi.wsdm.ManagementAgentContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlbeans.XmlObject;

public class XSULBasedNotifier implements  ManagementNotifier{
    protected static Log log = LogFactory.getLog(HasthiConstants.AGENT_LOGGER_NAME);
    private String name;
    //private SoapHttpDynamicInfosetInvoker invoker;
    private UnicastContianier contianier;
    private String eventSink;
    
    public XSULBasedNotifier(String eventSink, ManagementAgentContext agentContext) throws HasthiException {
        name = eventSink;
        this.eventSink = eventSink;
        contianier = agentContext.getUnicastContianier();
//        invoker = new SoapHttpDynamicInfosetInvoker();
//        invoker.setLocation(eventSink);
    }

    public String getName() {
        return name;
    }

    public void sendEvent(XmlObject eventData) throws HasthiException {
        SimpleMessageContext messageContext = new SimpleMessageContext(eventData,eventSink,"");
        contianier.send(messageContext);
//        invoker.invokeMessage(XBeansUtil.xmlObjectToXmlElement(eventData));
    }

    public boolean sendingEventFalied(Exception e) {
        log.warn(e);
        return true;
    }
    
    
    public void shutDown() throws HasthiException{
    }

    @Override
    public String toString() {
        return name;
    }
    
    
}
